package com.kolon.business.mOI_.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mOI_.controller.MOIExecJudgeWriteController")
public class MOIExecJudgeWriteController implements SimpleController {

	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mOI_/mOIExecJudgeWrite.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		// 도메인
		String url = MsgUtil.getMessage("xml.url");
		// 리턴 URL
		String returnUrl = request.getContextPath() + 
			"/business/mOI/mOIJudgeList.do";
		// 회원정보 세션 및 파라미터
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		String userId = (String)userMap.get("userId");
		String userPw = (String)userMap.get("userPw");
		String cpyCD = (String)userMap.get("CompanyCD");
		String seq = request.getParameter("seq");
		String page = request.getParameter("page");
		String endY = request.getParameter("endY");
		String pageGubun = request.getParameter("pageGubun");
		String ExecEmpID = ComUtil.nullChk(request.getParameter("ExecEmpID"));
		String Class = ComUtil.nullChk(request.getParameter("Class"));
		String JoinerWeight = ComUtil.nullChk(request.getParameter("JoinerWeight"));
		String JudCode = ComUtil.nullChk(request.getParameter("JudCode"));
		String JudOpinion = ComUtil.nullChk(request.getParameter("JudOpinion"), "");
		String SearchAuth = ComUtil.nullChk(request.getParameter("SearchAuth"));
		StringBuffer buffer = new StringBuffer();
		buffer = new StringBuffer();
		buffer.append(url);
		buffer.append("/oi_suggestion.aspx?strGubun=ExecReg&Seq=0");
		buffer.append("&ESeq=").append(seq);
		buffer.append("&a_pmode=jlist&ExecEmpID=").append(ExecEmpID);
		buffer.append("&Class=").append(Class);
		buffer.append("&JoinerWeight=").append(JoinerWeight);
		buffer.append("&JudCode=").append(JudCode);
		buffer.append("&SearchAuth=").append(SearchAuth);
		buffer.append("&JudOpinion=").append(ComUtil.getEncode(JudOpinion, "EUC-KR"));
		buffer.append("&mode=3");
		buffer.append("&companycd=").append(cpyCD);
		ComUtil.getDocument(buffer.toString(), userId, userPw);
		// 리턴
		returnUrl = returnUrl + "?pageGubun="+pageGubun+"&page="+page+"&endY="+endY;
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("message", "완료되었습니다.");
		modelAndView.addObject("scriptType", "003");
		modelAndView.addObject("message_url", returnUrl);
		modelAndView.setViewName("/business/common/alert");
		return modelAndView;
	}

}
